package com.bdqn.vueboot.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bdqn.vueboot.entity.Furniture;
import com.bdqn.vueboot.entity.Furnituretype;
import com.bdqn.vueboot.entity.Static;
import com.bdqn.vueboot.entity.SysUser;
import com.bdqn.vueboot.service.FurnitureServices;
import com.bdqn.vueboot.service.FurnituretypeService;
import com.bdqn.vueboot.service.StaticService;
import com.bdqn.vueboot.service.SysUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/furniture")
@RestController
public class FurnitureController {

    @Resource
    FurnitureServices furnitureServices;
    @Resource
    FurnituretypeService furnituretypeService;
    @Resource
    SysUserService sysUserService;
    @Resource
    StaticService staticService;

    @RequestMapping("/list")
    @CrossOrigin
    public Map list(@RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,
                    @RequestParam(value = "furnitureService", required = false, defaultValue = "0") Integer furnitureService,
                    @RequestParam(value = "furnitureAddress", required = false, defaultValue = "") String furnitureAddress,
                    @RequestParam(value = "furnitureUsrid", required = false, defaultValue = "0") Integer furnitureUsrid,
                    @RequestParam(value = "furnitureStaticid", required = false, defaultValue = "0") Integer furnitureStaticid,
                    @RequestParam(value = "creationTime", required = false, defaultValue = "") String creationTime,
                    @RequestParam(value = "limit", required = false, defaultValue = "5") Integer limit) {
        IPage<Furniture> furnitureIPage = furnitureServices.queryFurnitureLitBiz(furnitureService, furnitureAddress, furnitureUsrid, furnitureStaticid, creationTime, pageIndex, limit);
        Map map = new HashMap();
        map.put("furnitureIPage", furnitureIPage);
        List<Furnituretype> furnitureTypeList = furnituretypeService.quertFurniturelist();
        map.put("furnitureTypeList", furnitureTypeList);
        List<SysUser> sysUserList = sysUserService.list();
        map.put("sysUserList", sysUserList);
        List<Static> staticList = staticService.queryFurnitureStatic();
        map.put("staticList", staticList);
        return map;
    }

    @PostMapping("/seva")
    @CrossOrigin
    public int seva(@RequestBody Furniture furniture) throws Exception {
//        SysUser sysUser = sysUserService.findByUserIdBiz(Long.parseLong(furniture.getFurnitureUsrid()));
//        furniture.setFurnitureDepid(sysUser.getDepId());
        System.out.println(furniture);
        furniture.setFurnitureStaticid(41L);
        return furnitureServices.seva(furniture);
    }

    @GetMapping("/delFurniture")
    @CrossOrigin
    public int delFurniture(@RequestParam(value = "furnitureId") Long furnitureId, @RequestParam(value = "isDel") Long isDel) {
        return furnitureServices.delFurniture(furnitureId, isDel);
    }

    @GetMapping("/audit")
    @CrossOrigin
    public int sevaAudit(@RequestParam(value = "furnitureStaticId") Long furnitureStaticId, @RequestParam(value = "furnitureId") Long furnitureId) {
        return furnitureServices.sevaAudit(furnitureStaticId, furnitureId);
    }

}
